﻿using System.Windows;
using PSE.Deployment.ConfigurationManager.Controls.Validations;
using PSE.Deployment.SetupBase.Configuration;

namespace PSE.Deployment.ConfigurationManager.Controls
{
    /// <summary>
    /// UserControl que permite somente input no formato Uri
    /// </summary>
    public class FilePathTextBox : BaseSimpleTextBox
    {
        private FilePathTextBox()
        {
            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            this.VerticalAlignment = System.Windows.VerticalAlignment.Center;
        }

        public FilePathTextBox(XmlTag tag)
            : this()
        {
            this.DataContext = tag;
            ConfigurationBinding bd = new ConfigurationBinding();
            this.SetBinding(FilePathTextBox.TextProperty, bd);
            this.IsRequired = tag.IsRequired;
        }

        public FilePathTextBox(XmlAttribute attribute)
            : this()
        {
            this.DataContext = attribute;
            ConfigurationBinding bd = new ConfigurationBinding();
            this.SetBinding(FilePathTextBox.TextProperty, bd);
            this.IsRequired = attribute.IsRequired;
        }

        public FilePathTextBox(RegistryValue reg)
            : this()
        {
            this.DataContext = reg;
            ConfigurationBinding bd = new ConfigurationBinding();
            this.SetBinding(FilePathTextBox.TextProperty, bd);
            this.IsRequired = reg.IsRequired;
        }

        protected override bool Validate()
        {
            return SpecializedControlsValidations.IsFilePath(this.Text, false);
        }

        protected override ErrorMessage GetErrorMessage()
        {
            return ErrorMessage.InvalidFilePath;
        }
    }
}